//
//  HomeVC.swift
//  旅航ios
//
//  Created by tulip on 2021/4/21.
//

import UIKit

class HomeVC: UIViewController,UITableViewDelegate,UITableViewDataSource {
  
    @IBOutlet weak var table: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor=UIColor.white
        self.view.backgroundColor=UIColor.init(hexString: "f2f1f6")
        
        table.delegate=self
        table.dataSource=self
        table.separatorStyle = .none
        table.register(UINib.init(nibName: "BannerCell", bundle: nil), forCellReuseIdentifier: "BannerCell")
        table.register(UINib.init(nibName: "HcollectTableViewCell", bundle: nil), forCellReuseIdentifier: "HcollectTableViewCell")
        table.register(UINib.init(nibName: "ListTableViewCell", bundle: nil), forCellReuseIdentifier: "ListTableViewCell")
        if #available(iOS 11.0, *) {
            self.table.contentInsetAdjustmentBehavior = .never
        } else {
            automaticallyAdjustsScrollViewInsets = true
        }
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        2
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0{
            return 2
        }
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.section==0{
            if indexPath.row == 0 {
                let cell:BannerCell=tableView.dequeueReusableCell(withIdentifier: "BannerCell", for: indexPath) as! BannerCell
                return cell
            }
            if indexPath.row == 1 {
                let cell:HcollectTableViewCell=tableView.dequeueReusableCell(withIdentifier: "HcollectTableViewCell", for: indexPath) as! HcollectTableViewCell
                return cell
            }
        }
        if indexPath.section == 1 {
            let cell:ListTableViewCell=tableView.dequeueReusableCell(withIdentifier: "ListTableViewCell", for: indexPath) as! ListTableViewCell
            return cell
        }
        return UITableViewCell.init()
    }
  
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
            if indexPath.row == 0{
               return 550
            }
            if indexPath.row == 1{
               return 98 //83+15
            }
        }
        
       
        
        return UITableView.automaticDimension //SCREEN_HEIGHT-TabBarHeight
       
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 1 {
            return 35
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header=UIView.init()
        let pointView=UIView.init(frame: CGRect(x: 15, y: 14, width: 5, height: 8))
        pointView.backgroundColor=UIColor.init(hexString: "ff8a00")
        header.addSubview(pointView)
        
        let title=UILabel.init(frame: CGRect(x: 25, y: 9, width: 75, height: 18))
        title.text="热门推荐"
        title.font=UIFont.boldSystemFont(ofSize: 17)
        title.textColor=UIColor.black
        header.addSubview(title)
        
        let lab=UILabel.init(frame: CGRect(x: 108, y: 12, width: 150, height: 12))
        lab.text="每一次推荐都是精挑细选"
        lab.font=UIFont.systemFont(ofSize: 12)
        lab.textColor=UIColor.init(hexString: "a3a5a9")
        header.addSubview(lab)
        
        
        return header
    }
    
    
    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.isNavigationBarHidden = true
    }
}
